package com.example.quartz.demo.config;


import com.example.quartz.demo.factory.MyJobFactory;
import org.quartz.Scheduler;
import org.quartz.ee.servlet.QuartzInitializerListener;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.quartz.SchedulerFactoryBean;

import java.io.IOException;

@Configuration
public class QuartzConfig {

  @Autowired
 private MyJobFactory myJobFactory;


 @Bean
  public SchedulerFactoryBean schedulerFactoryBean() {
  SchedulerFactoryBean schedulerFactoryBean = new SchedulerFactoryBean();
  // 延时启动
  schedulerFactoryBean.setStartupDelay(20);
  schedulerFactoryBean.setJobFactory(myJobFactory);
 System.out.println("myJobFactory:"+myJobFactory);
  return schedulerFactoryBean;
 }
 @Bean
 public Scheduler scheduler() {
  return schedulerFactoryBean().getScheduler();
 }

}